// lib/api/subscription.api.dart
import 'package:xrenovation/utils/http.dart';

class SubscriptionApi {
  // 获取订阅产品信息
  static Future<Map<String, dynamic>> getProducts() async {
    final res = await Http.get('/subscription/products');
    return res.data;
  }

  // 验证iOS收据
  static Future<Map<String, dynamic>> verifyIosReceipt(
    String receiptData, {
    bool isSandbox = false,
  }) async {
    final res = await Http.post('/subscription/verify-ios', {
      'receipt_data': receiptData,
      'is_sandbox': isSandbox,
    });
    return res.data;
  }

  // 免费试用
  static Future<Map<String, dynamic>> freeTrial(
    String purchaseToken,
    String productId,
    String packageName,
  ) async {
    final res = await Http.post('/subscription/freeTrial', {
      'purchase_token': purchaseToken,
      'product_id': productId,
      'package_name': packageName,
    });
    return res.data;
  }

  // 验证Google Play订单
  static Future<Map<String, dynamic>> verifyGooglePlayOrder(
    String purchaseToken,
    String productId,
    String packageName,
  ) async {
    final res = await Http.post('/subscription/verify-android', {
      'purchase_token': purchaseToken,
      'product_id': productId,
      'package_name': packageName,
    });
    return res.data;
  }

  // 获取当前订阅状态
  static Future<Map<String, dynamic>> getSubscriptionStatus() async {
    final res = await Http.get('/subscription/status');
    return res.data;
  }

  // 恢复购买（iOS）
  static Future<Map<String, dynamic>> restorePurchases() async {
    final res = await Http.post('/subscription/restore', {});
    return res.data;
  }
}
